﻿/*
* Walking.cpp
*
* 行走
*
* create date: 2014.4.17
* create by: leo
*
*/

#include "Walking.h"

#include "../heros/BaseHero.h"

USING_NS_CC;
USING_NS_CC_EXT;

CBaseSkill* CWalking::create(Param& param)
{
	CWalking* skill = new CWalking(param);
	return skill;
}

void CWalking::use()
{
	mArmature->getAnimation()->playWithIndex(mAniIndex);
	mShadowArmature->getAnimation()->playWithIndex(mAniIndex);

	float dis = ccpDistance(mParam.BelongHero->getPosition(), mDestPos);
	mAction = mParam.BelongHero->runAction(CCSequence::create(CCMoveTo::create(dis / mParam.BelongHero->getMoveSpeed(), mDestPos),
														CCCallFuncO::create(this, callfuncO_selector(CWalking::onReachDest), mParam.BelongHero),
														NULL));
}

void CWalking::stop()
{
    if (NULL != mAction)
    {
	    mAction->stop();
    }
    mAction = NULL;
}

void CWalking::setDestination(int x, int y)
{
	mDestPos.x = x;
	mDestPos.y = y;
}

CWalking::CWalking(Param& param)
: CBaseSkill(param),
  mAction(NULL)
{
	mOnFinishCallback = (callfuncO_selector(CWalking::onReachDest));
	mParam.BelongHero->registerWalkingSkill(*this);
}

CWalking::~CWalking()
{}

void CWalking::onReachDest(CCObject* obj)
{
	CBaseHero* hero = (CBaseHero*)obj;
	hero->waiting();
}
